package com.app.business.global.thirdservice.icc.controller;

import com.app.business.global.thirdservice.icc.dto.req.*;
import com.app.business.global.thirdservice.icc.dto.res.*;
import com.app.business.global.thirdservice.icc.service.IccService;
import com.app.common.constant.ResultStatusEnum;
import com.app.common.dto.res.PageRes;
import com.app.common.dto.res.Result;
import com.dahuatech.icc.exception.ClientException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Validated
@Tag(name = "大华视频转发")
public class IccController {
    @Autowired
    private IccService iccService;
    
    @Operation(summary = "【分页查询设备通道】")
    @PostMapping("/public/pageEquipmentChannel")
    public Result<IccResult<PageRes<PageEquipmentChannelRes>>> pageEquipmentChannel(@RequestBody PageEquipmentChannelReq req) throws ClientException {
        IccResult<PageRes<PageEquipmentChannelRes>> result = iccService.pageEquipmentChannel(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【获取实时监控】")
    @PostMapping("/public/getRealMonitor")
    public Result<IccResult<GetRealMonitorRes>> getRealMonitor(@RequestBody GetRealMonitorReq req) throws ClientException {
        IccResult<GetRealMonitorRes> result = iccService.getRealMonitor(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【开始语音对讲】")
    @PostMapping("/public/startTalk")
    public Result<IccResult<StartTalkRes>> startTalk(@RequestBody StartTalkReq req) throws ClientException {
        IccResult<StartTalkRes> result = iccService.startTalk(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【停止语音对讲】")
    @PostMapping("/public/stopTalk")
    public Result<IccResult> stopTalk(@RequestBody StopTalkReq req) throws ClientException {
        IccResult result = iccService.stopTalk(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【获取一个月录像存在状态】")
    @PostMapping("/public/getRecordStateByMonth")
    public Result<IccResult<GetRecordStateByMonthRes>> getRecordStateByMonth(@RequestBody GetRecordStateByMonthReq req) throws ClientException {
        IccResult<GetRecordStateByMonthRes> result = iccService.getRecordStateByMonth(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【获取普通录像信息列表】")
    @PostMapping("/public/listSimpleRecord")
    public Result<IccResult<List<ListSimpleRecordRes>>> listSimpleRecord(@RequestBody ListSimpleRecordReq req) throws ClientException {
        IccResult<List<ListSimpleRecordRes>> result = iccService.listSimpleRecord(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【根据文件获取录像回放】")
    @PostMapping("/public/getRecordByFile")
    public Result<IccResult<GetRecordByFileRes>> getRecordByFile(@RequestBody GetRecordByFileReq req) throws ClientException {
        IccResult<GetRecordByFileRes> result = iccService.getRecordByFile(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【根据时间获取录像回放】")
    @PostMapping("/public/getRecordByTime")
    public Result<IccResult<GetRecordByTimeRes>> getRecordByTime(@RequestBody GetRecordByTimeReq req) throws ClientException {
        IccResult<GetRecordByTimeRes> result = iccService.getRecordByTime(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【云台镜头控制】")
    @PostMapping("/public/setPtzCamera")
    public Result<IccResult> setPtzCamera(@RequestBody SetPtzCameraReq req) throws ClientException {
        IccResult result = iccService.setPtzCamera(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【云台方向控制】")
    @PostMapping("/public/setPtzDirection")
    public Result<IccResult> setPtzDirection(@RequestBody SetPtzDirectionReq req) throws ClientException {
        IccResult result = iccService.setPtzDirection(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
    
    @Operation(summary = "【云台三维定位】")
    @PostMapping("/public/setPtzPosition")
    public Result<IccResult> setPtzPosition(@RequestBody SetPtzPositionReq req) throws ClientException {
        IccResult result = iccService.setPtzPosition(req);
        if (result.getSuccess() != null && result.getSuccess()) {
            return Result.success(result);
        } else {
            return Result.failure(result).setCode(ResultStatusEnum.THIRD_ERROR.getCode()).setMsg(ResultStatusEnum.THIRD_ERROR.getMsg());
        }
    }
}
